Skip to content

Add metric: average number of problems per division - #101

Merged
deyna256 merged 1 commit into
deyna256:mainfrom
DebuggingMax:100
Mar 3, 2026
Merged

Add metric: average number of problems per division#101
deyna256 merged 1 commit into
deyna256:mainfrom
DebuggingMax:100

Conversation

@DebuggingMax

@DebuggingMax DebuggingMax commented Feb 26, 2026

Copy link
Copy Markdown
Contributor

Summary

Closes #100

This PR adds a new metric that calculates the average number of problems solved per contest for each division (Div. 1, Div. 2, Div. 3, Div. 4).

Changes

New Files

  • backend/domain/models/division_problems.py - Domain models for division analysis
  • backend/domain/services/division_problems_service.py - Service to analyze submissions by division
  • backend/api/routes/division_problems.py - API route handler
  • backend/api/schemas/division_problems.py - Pydantic schemas for API response
  • backend/tests/unit/division_problems_service/ - Unit tests for the service
  • backend/tests/unit/codeforces_client/test_extract_division.py - Tests for division extraction

Modified Files

  • backend/infrastructure/codeforces_client.py - Added get_contest_divisions() method with division extraction from contest names
  • backend/services/codeforces_data_service.py - Added method to expose contest divisions
  • backend/api/deps.py - Added dependency provider for new service
  • backend/api/routes/__init__.py - Registered new controller
  • backend/domain/models/__init__.py - Exported new models
  • backend/domain/services/__init__.py - Exported new service

API Endpoint

GET /api/division-problems/{handle}

Response Example

{
  "divisions": [
    {
      "division": "Div. 1",
      "contest_count": 5,
      "total_problems_solved": 8,
      "average_problems_per_contest": 1.6
    },
    {
      "division": "Div. 2",
      "contest_count": 20,
      "total_problems_solved": 65,
      "average_problems_per_contest": 3.25
    }
  ],
  "total_contests": 25,
  "total_problems_solved": 73,
  "last_updated": "2024-01-15T12:00:00Z"
}

Implementation Details

  • Fetches contest list from Codeforces API to build a mapping of contest_id → division
  • Caches the division mapping globally to avoid repeated API calls
  • Extracts division from contest names using regex (handles "Div. 1", "Div. 2", etc.)
  • For combined rounds (e.g., "Div. 1 + Div. 2"), uses the harder division (lower number)
  • Follows existing patterns for caching, staleness handling, and async task queueing

@deyna256

This adds a new API endpoint /api/division-problems/{handle} that calculates
the average number of problems solved per contest for each division (Div. 1-4).

Changes:
- Add DivisionProblemsService to analyze submissions by division
- Add CodeforcesClient.get_contest_divisions() to fetch and cache division info
- Add API endpoint with schema and route following existing patterns
- Add comprehensive tests for the new functionality

The metric extracts division information from contest names (e.g., 'Div. 1',
'Div. 2') and calculates per-contest averages to help users understand their
performance across different difficulty levels.
@DebuggingMax

Copy link
Copy Markdown
Contributor Author

Hey @deyna256! 👋

This PR implements the metric requested in #100 - average number of problems per division.

Key features:

  • New endpoint /api/division-problems/{handle}
  • Extracts division info from contest names (Div. 1-4)
  • Calculates average problems solved per contest for each division
  • Follows existing patterns (caching, staleness handling, async tasks)
  • Includes comprehensive tests

Ready for review! Let me know if you'd like any changes.

@deyna256 deyna256 left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@deyna256
deyna256 merged commit 28f5c08 into deyna256:main Mar 3, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Metric: avg number of problems per division

2 participants